package com.ml.mall.api.sys;

import com.ml.mall.annotations.OperLog;
import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.sys.SysRolePermQueryDto;
import com.ml.mall.bean.req.sys.SysRolePermissionDto;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.service.sys.ISysRolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
* <p>
    * 角色权限对应关系表 前端控制器
    * </p>
*
* @author kyyang
* Created 2021-01-20
*/

@Api(tags = "【auth】角色权限")
@RestController
@RequestMapping("/role_permission")
public class SysRolePermissionController extends BaseController {

     @Autowired
     private ISysRolePermissionService sysRolePermissionService;


    @RequestMapping(method = RequestMethod.POST, path = "/query")
    @ApiOperation("角色权限查询")
//  @RequiresPermissions(PermissionConst.ROLE_PERMISSION_QUERY)
    public ApiRestResult sysRolePermissionQuery(@Valid @RequestBody SysRolePermQueryDto sysRolePermQueryDto) {
        return ApiRestResult.ok(sysRolePermissionService.sysRolePermission(sysRolePermQueryDto));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "角色权限新增", operModul = "role_permission", operType = "new")
    @ApiOperation("角色权限新增")
//  @RequiresPermissions(PermissionConst.ROLE_PERMISSION_NEW)//操作整合到角色编辑接口中
    public ApiRestResult sysRolePermissionNew(@Valid @RequestBody SysRolePermissionDto sysRolePermissionDto ) {
        return ApiRestResult.ok(sysRolePermissionService.sysRolePermissionNew(sysRolePermissionDto));
    }


    @RequestMapping(method = RequestMethod.DELETE, path = "/del")
    @OperLog(operDesc = "角色权限删除", operModul = "role_permission", operType = "del")
    @ApiOperation("角色权限删除")
//  @RequiresPermissions(PermissionConst.ROLE_PERMISSION_DEL)//操作整合到角色编辑接口中
    public ApiRestResult sysRolePermissionDel(@Valid @RequestBody SysRolePermissionDto sysRolePermissionDto ) {
        return ApiRestResult.ok(sysRolePermissionService.sysRolePermissionDel(sysRolePermissionDto));
    }
}
